package com.hs;

import com.hs.entity.User;
import com.hs.mapper.UserMapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

import java.util.List;

/**
 * @author fuyanru
 * @date 2024年04月28日 21:38
 */
@SpringBootTest
public class testRedis {
    @Autowired
    private UserMapper userMapper;
    @Test
    public void testUserMapper(){
        List<User> userList = userMapper.selectList(null);
        System.out.println(userList);
    }

//    @Autowired
//    private PasswordEncoder passwordEncoder;

    @Test
    public void testBCryptPasswordEncoder(){
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        // passwordEncoder.encode(String password) 对密码进行加密
//        String encode = passwordEncoder.encode("123456");
//        System.out.println(encode);
//          $2a$10$qZ7UXOTlAjKcHNotJUKEMeccnq6RlzPgRsxA.3jLVCFYPM9XFcfQ2
        // passwordEncoder.matches(String password, String encodedPassword) 使用明文密码和加密后的密码进行比对
        boolean b = passwordEncoder.matches("123456", "$2a$10$qZ7UXOTlAjKcHNotJUKEMeccnq6RlzPgRsxA.3jLVCFYPM9XFcfQ2");
        System.out.println(b);
    }
}
